<?php

/**
 * Description of ViewHead
 *
 * @author Ian Clarence <ian.clarence@gmail.com>
 */
class ViewHead extends ViewHtmlElement {

    /**
     * The constructor.
     *
     * @param array $fields
     */
    public function __construct(array $fields = array()) {

        $fields["tag"] = "head";
        
        parent::__construct($fields);
        
        /**
         * Title.
         */
        if (isset($this->fields["title_text"])) {
            $title = ViewHtmlElement::elementInit("title", $this->getTitleText());
            $this->addInnerHtml($title);
        }

        /**
         * Author.
         */
        $author = new ViewMeta();
        // $this->addInnerHtml($author);

        /**
         * Character set and content type.
         */
        $httpEquiv = new ViewMeta(array(
            "name" => "http_equiv",
            "content" => ViewMeta::CHAR_SET . CHARSET . "; " . ViewMeta::CONTENT_TYPE
        ));
        $this->addInnerHtml($httpEquiv);

        /**
         * Stylesheets.
         */
        if (isset($this->fields["stylesheets"])) {
            if (is_array($this->fields["stylesheets"])) {
                foreach ($this->getStylesheets() as $stylesheetKey => $stylesheet) {
                    $this->addInnerHtml(new ViewLink(array("src" => $stylesheet)));
                }
            }
        }

        /**
         * JavaScript files.
         */
        if (isset($this->fields["scripts"])) {
            if (is_array($this->fields["scripts"])) {
                foreach ($this->scripts as $scriptKey => $script) {
                    $this->addInnerHtml(new ViewScript(array("src" => $script)));
                }
            }
        }
        
    }

}